#ifndef BASE_TIMEUNIT_H
#define BASE_TIMEUNIT_H

#include <cstdint>
#include <sys/time.h>
#include <string>

namespace DBServer {
namespace Base {
namespace Timer
{
class Time {
public:
    // for logger
    static char* GET_CUR();

public:

    Time();
    ~Time() = default;
    Time(Time&) = default;
    auto operator=(const Time&) -> void;

    auto format() -> std::string;

    auto operator-(Time&) -> Time;
    auto operator>(Time&) -> bool;
    auto operator<(Time&) -> bool;
    auto operator==(Time&) -> bool;
    auto operator>=(Time&) -> bool;
    auto operator<=(Time&) -> bool;
    auto operator-=(long long) -> void;
    auto operator+=(long long) -> void;

    auto later(long long) -> void;
    auto cur() -> void;
    auto is_timeout() -> bool;

    auto get_time() -> long long;
    auto get_time_ms() -> std::uint64_t;
    auto get_time_us() -> std::uint64_t;

private:
    Time(const struct timeval&);

private:
    struct timeval tv;
    struct timezone tz;
};

} // namespace Timer
} // namespace Base
} // namespace DBServer

#endif